package com.sxpi.zixun.controller.course;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxpi.zixun.aspect.log.PugLog;
import com.sxpi.zixun.bo.CourseBo;
import com.sxpi.zixun.common.anno.IgnoreToken;
import com.sxpi.zixun.common.enums.AdminUserResultEnum;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.Course;
import com.sxpi.zixun.service.course.ICourseService;
import com.sxpi.zixun.vo.CourseStatusUpdateVo;
import com.sxpi.zixun.vo.CourseVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/5 19:53
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="课程",tabname="kss_course")
public class CourseController extends BaseController {

    private final ICourseService courseService;

/*
    日志测试 限流
    @GetMapping("/course/load")
    @PugDoc(name="查询课程列表信息并分页")
    @PugLog(value = "course",desc = "查询课程列表信息并分页")
    @IgnoreToken
    public IPage<CourseBo> findCourses(CourseVo courseVo) {
        return courseService.findCoursePage(courseVo);
    }
*/
    /**
     * 查询课程列表信息并分页
     * @param courseVo
     * @return
     */
    @PostMapping("/course/load")
    @PugDoc(name="查询课程列表信息并分页")
    public IPage<CourseBo> findCourses(@RequestBody CourseVo courseVo) {
        return courseService.findCoursePage(courseVo);
    }

    /**
     * 拷贝课程信息
     * @param courseId
     * @return
     */
    @PostMapping("/course/copy/{courseId}")
    @PugDoc(name = "拷贝课程信息")
    public CourseBo copyChapterLesson(@PathVariable("courseId") String courseId) {
        Course course = courseService.getById(new Long(courseId));
        if (course != null) {
            course.setId(null);
            course.setStatus(0);
            course.setIsdelete(0);
            return courseService.saveupdateCourse(course);
        }
        return null;
    }

    /**
     * 根据课程id查询明细信息
     * @param id
     * @return
     */
    @PostMapping("/course/get/{id}")
    @PugDoc(name="根据课程id查询明细信息")
    public CourseBo getCourseById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id,ResultStatusEnum.ID_NOT_EMPTY);
        return courseService.getCourseById(new Long(id));
    }

    /**
     * 保存和修改课程
     * @param course
     * @return
     */
    @PostMapping("/course/saveupdate")
    @PugDoc(name="保存和修改课程")
    public CourseBo saveUpdateCourse(@RequestBody Course course) {
        return courseService.saveUpdateCourse(course);
    }

    /**
     * 根据课程id删除课程
     * @param id
     * @return
     */
    @PostMapping("/course/delete/{id}")
    @PugDoc(name="根据课程id删除课程")
    public int deleteCourseById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id,ResultStatusEnum.ID_NOT_EMPTY);
        return courseService.deleteCourseById(new Long(id));
    }

    /**
     * 根据课程ids批量删除课程
     * @param courseVo
     * @return
     */
    @PostMapping("/course/delBatch")
    @PugDoc(name="根据课程ids批量删除课程")
    public boolean deleteCourse(@RequestBody CourseVo courseVo) {
        Vsserts.isEmptyEx(courseVo.getBatchIds(),ResultStatusEnum.ID_NOT_EMPTY);
        return courseService.deleteBatchCourse(courseVo.getBatchIds());
    }

    /**
     * 用于状态更新
     * @param courseStatusUpdateVo
     * @return
     */
    @PostMapping("/course/update")
    @PugDoc(name = "用于状态更新")
    public boolean updateAdminRole(@RequestBody CourseStatusUpdateVo courseStatusUpdateVo) {
        Vsserts.isNullEx(courseStatusUpdateVo.getId(), AdminUserResultEnum.NULL_ERROR);
        return courseService.updateAdminRole(courseStatusUpdateVo);
    }

    /**
     * 查询课程列表信息
     * @return
     */
    @PostMapping("/course/list")
    @PugDoc(name="查询课程列表信息")
    @PugLog(value="course",desc = "查询课程列表信息")
    public List<CourseBo> findCourseList() {
        return courseService.findCourseList();
    }

}
